﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using intelliPaper.DB;
using intelliPaper.Model;
using intelliPaper.DB;


namespace intelliSys.Management.Automation.Test
{
    static class DataRepository
    {
        public static List<KnowledgePoint> KnowledgePoints;
        public static List<Question> Questions;
        public static List<Paper> Papers;

        public static string StartFilePath="";
        public static bool IsOpenFromFile = false;

        public static void Load()
        {
            KnowledgePoints = Dao.GetAllKnowledgePoints();
            Questions = Dao.GetAllQuestions();
            Papers = Dao.GetAllPapers();
           Helper.InitialKnowledgePointInQuestions(KnowledgePoints, Questions);
        }
    }
    static class Extension
    {
        public static void Restore(this KnowledgePoint knowledgePoint, KnowledgePoint backUp)
        {
            knowledgePoint.CreateDate = backUp.CreateDate;
            knowledgePoint.ID = backUp.ID;
            knowledgePoint.Importance = backUp.Importance;
            knowledgePoint.IsEnabled = backUp.IsEnabled;
            knowledgePoint.IsOpenXMLEnabled = backUp.IsOpenXMLEnabled;
            knowledgePoint.KnowledgeDifficulty = backUp.KnowledgeDifficulty;
            knowledgePoint.KnowledgePointBody = backUp.KnowledgePointBody;
            knowledgePoint.UseFrequency = backUp.UseFrequency;
        }
        public static void Restore(this Question question, Question backUp)
        {
            question.CreateDate = backUp.CreateDate;
            question.ErrorAnswers = backUp.ErrorAnswers;
            question.HistoryMessages = backUp.HistoryMessages;
            question.ID = backUp.ID;
            question.IsEnabled = backUp.IsEnabled;
            question.IsOpenXMLEnabled = backUp.IsOpenXMLEnabled;
            question.KnowledgePoints = backUp.KnowledgePoints;
            question.LastUsed = backUp.LastUsed;
            question.Possiblity = backUp.Possiblity;
            question.QuestionBody = backUp.QuestionBody;
            question.QuestionType = backUp.QuestionType;
            question.StartDifficulty = backUp.StartDifficulty;
            question.TrueAnswers = backUp.TrueAnswers;
        }
        public static void Restore(this Paper paper, Paper backUp)
        {
            paper.Difficulty = backUp.Difficulty;
            paper.ID = backUp.ID;
            paper.Introduction = backUp.Introduction;
            paper.IsEnabled = backUp.IsEnabled;
            paper.KnowledgePoints = backUp.KnowledgePoints;
            paper.LastModifyDate = backUp.LastModifyDate;
            paper.Questions = backUp.Questions;
            paper.TestDate = backUp.TestDate;
        }
        public static Question CreateDeepCopy(this Question backUp)
        {
            Question question = new Question();
            question.CreateDate = backUp.CreateDate;
            question.ErrorAnswers = backUp.ErrorAnswers.ToList();
            question.HistoryMessages = backUp.HistoryMessages.ToList();
            question.ID = backUp.ID;
            question.IsEnabled = backUp.IsEnabled;
            question.IsOpenXMLEnabled = backUp.IsOpenXMLEnabled;
            question.KnowledgePoints = backUp.KnowledgePoints.ToList();
            question.LastUsed = backUp.LastUsed;
            question.Possiblity = backUp.Possiblity;
            question.QuestionBody = backUp.QuestionBody;
            question.QuestionType = backUp.QuestionType;
            question.StartDifficulty = backUp.StartDifficulty;
            question.TrueAnswers = backUp.TrueAnswers.ToList();
            question.Summary = backUp.Summary;
            return question;
        }
        public static Paper CreateDeepCopy(this Paper backUp)
        {
            Paper paper = new Paper();
            paper.Difficulty = backUp.Difficulty;
            paper.ID = backUp.ID;
            paper.Introduction = backUp.Introduction;
            paper.IsEnabled = backUp.IsEnabled;
            paper.KnowledgePoints = backUp.KnowledgePoints.ToList();
            paper.LastModifyDate = backUp.LastModifyDate;
            paper.Questions = backUp.Questions.ToList();
            paper.TestDate = backUp.TestDate;
            return paper;
        }
        public static KnowledgePoint CreateDeepCopy(this KnowledgePoint backUp)
        {
            KnowledgePoint knowledgePoint = new KnowledgePoint();
            knowledgePoint.CreateDate = backUp.CreateDate;
            knowledgePoint.ID = backUp.ID;
            knowledgePoint.Importance = backUp.Importance;
            knowledgePoint.IsEnabled = backUp.IsEnabled;
            knowledgePoint.IsOpenXMLEnabled = backUp.IsOpenXMLEnabled;
            knowledgePoint.KnowledgeDifficulty = backUp.KnowledgeDifficulty;
            knowledgePoint.KnowledgePointBody = backUp.KnowledgePointBody;
            knowledgePoint.UseFrequency = backUp.UseFrequency;
            return knowledgePoint;
        }
    }
}
